package com.uphone.magicleafteacher.pro.activity;

import android.view.View;

import com.blankj.utilcode.util.SizeUtils;
import com.radish.baselibrary.Intent.IntentData;
import com.radish.baselibrary.Intent.IntentUtils;
import com.uphone.magicleafteacher.MyApp;
import com.uphone.magicleafteacher.base.BaseListActivity;
import com.uphone.magicleafteacher.http.ApiService;
import com.uphone.magicleafteacher.pro.activity.listenertraining.ListenerTrainingActivity;
import com.uphone.magicleafteacher.pro.activity.listenertrainscore.ListenerTrainScoreActivity;
import com.uphone.magicleafteacher.pro.adapter.ListenerTrainAdapter;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.GsonUtils;
import com.uphone.magicleafteacher.vo.AudioSubmitBean;
import com.uphone.magicleafteacher.vo.ListenerTrainEvent;
import com.uphone.magicleafteacher.vo.WorkcorrectionEvent;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class ListenerTrainActivity extends BaseListActivity<AudioSubmitBean.AudioWorkListBean, ListenerTrainAdapter> {


    @IntentData
    private int id;
    @IntentData
    private String title;

    @Override
    protected void initLayoutBefore() {
        isEventBus = true;
        super.initLayoutBefore();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefresh(ListenerTrainEvent event) {
        //刷新
        initData();
    }

    @Override
    protected Observable<ResponseBody> loadData(ApiService apiService) {
        return MyApp.apiService(ApiService.class)
                .submitList(id + "", page + "", "10");
    }

    @Override
    protected List<AudioSubmitBean.AudioWorkListBean> getDataList(String json) {
        AudioSubmitBean bean = GsonUtils.getGson().fromJson(json, AudioSubmitBean.class);
        if (bean != null)
            return bean.getAudioWorkList();
        return null;
    }

    @Override
    protected void itemClick(ListenerTrainAdapter adapter, View view, int position) {
        AudioSubmitBean.AudioWorkListBean item = adapter.getItem(position);
        int remakStatus = item.getRemakStatus();
        if (remakStatus == 1) {//已通过未打分
            IntentUtils.getInstance().with(this, ListenerTrainScoreActivity.class)
                    .putString("title", title)
                    .putString("id", item.getWorkId() + "")
                    .start();

        } else if (remakStatus == 2 || remakStatus == 3) {//已打分
            IntentUtils.getInstance().with(this, MytrainingdetailsActivity.class)
                    .putString("title", title)
                    .putString("id", item.getWorkId() + "")
                    .start();
        } else { // 未批改
            IntentUtils.getInstance().with(this, ListenerTrainingActivity.class)
                    .putString("title", title)
                    .putString("id", item.getWorkId() + "")
                    .start();
        }
    }

    @Override
    protected ListenerTrainAdapter initAdapter() {
        return new ListenerTrainAdapter();
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected void initTitle() {
        initTitle(CommonUtil.getStr(title));
        recyclerView.setPadding(0, SizeUtils.dp2px(5), 0, 0);
    }
}
